<template>
  <a-table :customRow='customRow' :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps:getCheckboxProps }"
    :columns="columns" :data-source="dataSource" />
</template>
<script>
export default {
  props: {
    dataSource: Array,
    columns: Array,
  },
  data() {
    return {
      selectedRowKeys: [],
    };
  },
  methods: {
    customRow(record) {
      return {
        on: {
          // 单击
          click: () => {
            this.selectedRowKeys.push(record.key);
            this.selectedRowKeys = [...new Set(this.selectedRowKeys)];
            this.$emit("handClick", this.selectedRowKeys);
          },
          // 双击
          dblclick: () => {
            let index = this.selectedRowKeys.findIndex((arg) => {
              return arg == record.key;
            });
            this.selectedRowKeys.splice(index, 1);
            this.$emit("handClick", this.selectedRowKeys);
          },
        },
      };
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
      this.$emit("handClick", this.selectedRowKeys);
    },
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.name === "Disabled User",
          name: record.name,
        },
      };
    },
  },
};
</script>
